package net.qhzw.geologr5.gis.service.system.controller;

import net.qhzw.geologr5.gis.common.framework.utils.JsonResult;
import net.qhzw.geologr5.gis.service.system.query.ProjectDataQuery;
import net.qhzw.geologr5.gis.service.system.service.ProjectItemService;
import net.qhzw.geologr5.gis.service.system.service.ProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/****
 * 项目管理 前端控制器
 */
@RestController
@RequestMapping("/project")
public class ProjectController {


    @Autowired
    private ProjectService projectService;

    @Autowired
    private ProjectItemService projectItemService;


    /***
     * 导入excel
     * @return
     */
    @PostMapping("importExcel")
    public JsonResult importExcel(@RequestParam("file") MultipartFile file, @RequestParam Integer projectId) {
        if (file.getOriginalFilename().endsWith(".xlsx") || file.getOriginalFilename().endsWith(".xls")) {
            return projectService.importExcel(file, projectId);
        } else {
            return JsonResult.error("上传文件的格式有误");
        }

    }


    /***
     * 项目资料上传
     * @param file
     * @return
     */
    @PostMapping("upload")
    public JsonResult upload(@RequestParam("file") MultipartFile file, @RequestParam String sign) {
        if (file.getOriginalFilename().endsWith(".zip"))
            return projectService.upload(file, sign);
        return JsonResult.error("上传文件的格式有误");
    }

    /***
     * 匹配上传资料
     * @return
     */
    @PostMapping("matching")
    public JsonResult matching(@RequestParam String verify) {
        return projectService.matching(verify);
    }


    /***
     * 项目资料上传完毕,清理零时文件
     * @return
     */
    @GetMapping("destroy")
    public JsonResult destroy(@RequestParam String verify) {
        return projectService.destroy(verify);
    }


    /***
     * 项目资料查看
     * @return
     */
    @GetMapping("selectProjectData")
    public JsonResult selectProjectData(ProjectDataQuery query) {
        return projectItemService.selectProjectData(query);
    }


    /****
     * 上传项目资料
     * @return
     */
    @PostMapping("uploadProjectInfo")
    public JsonResult uploadProjectInfo(@RequestParam("file") MultipartFile file, @RequestParam Integer projectId){
        return projectService.uploadProjectInfo(file, projectId);
    }

}
